package diploma.kisel.modelas.service;

import java.util.List;

import diploma.kisel.modelas.domain.Database;
import diploma.kisel.modelas.repository.DatabaseRepositoryImpl;
import diploma.kisel.modelas.repository.api.DatabaseRepository;
import diploma.kisel.modelas.service.api.DatabaseService;

public class DatabaseServiceImpl implements DatabaseService{
	
	private DatabaseRepository databaseRepository = new DatabaseRepositoryImpl();

	@Override
	public List<Database> findAll() {
		return databaseRepository.findAll();
	}

	@Override
	public Database findById(int id) {
		if (id>=0)
			return databaseRepository.findById(id);
		else
			return null;
	}

	@Override
	public Database save(Database database) {
		if (database.getId()!=null)
			return databaseRepository.update(database);
		else
			return databaseRepository.save(database);
	}

	@Override
	public void remove(Database database) {
		if (database!=null && database.getId()!=null)
			databaseRepository.remove(database);		
		
	}

	@Override
	public void remove(int id) {
		Database database = findById(id);
		remove(database);		
	}

}
